package com.ccp.dev.system.model;

import com.ccp.dev.core.basic.api.ISysOrg;
import com.ccp.dev.core.basic.consts.SystemConst;
import com.ccp.dev.core.basic.model.BaseModel;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
/**
 * 对象功能:组织架构SYS_ORG Model对象
 * @author :pkq
 * 创建时间:2011-11-09 11:20:13
 */
@Repository
public class SysOrgChildren extends BaseModel implements ISysOrg {
	
	private static final long serialVersionUID = 1L;
	/**
	 * 默认维度
	 */
	public final static Long BEGIN_DEMID=1L;
	/**
	 * 默认组织ID
	 */
	public final static Long BEGIN_ORGID=1L;
	/**
	 * 默认深度
	 */
	public final static Integer BEGIN_DEPTH=0;
	/**
	 * 默认路径
	 */
	public final static String BEGIN_PATH="1";
	/**
	 * 默认组织类型
	 */
	public final static Short BEGIN_TYPE=1;
	/**
	 * 默认组织父ID
	 */
	public final static Long BEGIN_ORGSUPID=-1L;
	/**
	 * 默认sn
	 */
	public final static Short BEGIN_SN=1;
	/**
	 * 默认组织类型
	 */
	public final static Short BEGIN_FROMTYPE=0;

	public final static Short FROMTYPE_AD=1;
	public final static Short FROMTYPE_DB=0;
	/**
	 * 不是叶子节点
	 */
	public final static Integer IS_LEAF_N=1;
	/**
	 * 是叶子节点
	 */
	public final static Integer IS_LEAF_Y=0;
	/**
	 * 不是父类节点
	 */
	public final static Boolean IS_PARENT_N=false;
	/**
	 * 是父类节点
	 */
	public final static Boolean IS_PARENT_Y=true;

	/**
	 * 不是租户
	 */
	public final static int IS_TENANT_N=0;
	/**
	 * 是租户
	 */
	public final static int IS_TENANT_Y=1;


	/**
	 * 组织ID
	 */
	private String orgId;
	/**
	 * 维度编号
	 */
	private String demId;
	/**
	 * 维度名称
	 */
	private String demName; 
	/**
	 * 名称
	 */
	private String orgName;
	/**
	 * 描述
	 */
	private String orgDesc;
	/**
	 * 组织路径
	 */
	private String orgPathname;
	/**
	 * 上级
	 */
	private String orgSupId;
	/**
	 * 上级组织代码(表中无此字段)
	 */
	private String supCode;
	/**
	 * 上级组织名称(如果等于维度ID则说明该组织是该维度的根节点)
	 */
	private String orgSupName;	
	/**
	 * 路径
	 */
	private String path;
	/**
	 * 层次
	 */
	private Integer depth;
	/**
	 * 类型
	 */
	private Long orgType;
	/**
	 * 建立人
	 */
	private String creatorId;
	/**
	 * 建立时间
	 */
	private Date createtime;
	/**
	 * 修改人
	 */
	private String updateId;
	/**
	 * 修改时间
	 */
	private Date updateTime;
	/**
	 * 负责人id
	 */
	private String ownUser;	
	/**
	 * 负责人姓名
	 */
	private String ownUserName;	
	/**
	 * 创建人
	 */
	private String createName;
	/**
	 * 修改人
	 */
	private String updateName;
	/**
	 * 序号
	 */
	private Long sn=0L;
	/**
	 * 在线人数
	 */
	private Integer onlineNum=0;
	private Short isPrimary;
	/**
	 * 在线人数
	 */
	private Short isRoot=0;
	/**
	 * 数据来源（0，系统添加,1,来自AD同步)
	 */
	private Short fromType=0;
	/**
	 * 图标
	 */
	private String iconPath="";
	/**
	 * 树展开
	 */
	private String open="true";
	/**
	 * 是否叶子结点(0否,1是),主要用于数据库保存
	 */
	private Integer isLeaf;
	/**
	 * 是否父类,主要用于树的展示时用
	 */
	private Boolean isParent;


	/**
	 * 是否父类布尔型,主要用于树的展示时用
	 */
	private boolean isParentBoolean=false;
	
	private Short isDelete=0;
	/**
	 * 公司ID
	 */
	private String companyId;
	/**
	 * 公司名称
	 */
	private String company="";
	/**
	 * 组织代码
	 */
	private String code;
	/**
	 * 顶级的组织ID
	 */
	private String topOrgId;
	/**
	 * 编制人数
	 */
	private Integer orgStaff;
	/**
	 * 父组织ID
	 */
	private String parentTenantId;
	/**
	 * 是否是租户
	 */
    private int isTenant;

	/**
	 * 组织名称 for 组织树显示名称
	 */
	private String name;

	/**
	 * 组织节点跳转路径 for 组织树节点
	 */
    private String jump;

	/**
	 * 子组织
	 */
	private List<SysOrgChildren> children;
	/**
	 * ztree需要的父节点id
	 */
	private String pid;

	public String getPid() {
		return this.orgSupId;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public String getName() {
		if(1==isTenant){
			return   orgName + SystemConst.tenantImgIdentify;
		}
		return this.orgName;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getJump() {
		return jump;
	}

	public void setJump(String jump) {
		this.jump = jump;
	}

	public List<SysOrgChildren> getChildren() {
		if(null!=children && children.size()>0){
			return children;
		}
		return null;
	}

	public void setChildren(List<SysOrgChildren> children) {
		this.children = children;
	}

	public int getIsTenant() {
		return isTenant;
	}
	public void setIsTenant(int isTenant) {
		this.isTenant = isTenant;
	}
	
	public String getParentTenantId() {
		return parentTenantId;
	}
	public void setParentTenantId(String parentTenantId) {
		this.parentTenantId = parentTenantId;
	}
	
	public Short getIsDelete() {
		return isDelete;
	}
	public void setIsDelete(Short isDelete) {
		this.isDelete = isDelete;
	}
	public String getOpen() {
		return open;
	}
	public void setOpen(String open) {
		this.open = open;
	}
	public Integer getIsLeaf() {
		return isLeaf;
	}
	public void setIsLeaf(Integer isLeaf) {
		this.isLeaf = isLeaf;
		if(isLeaf!=null&&isLeaf==0){
			this.isParent=IS_PARENT_N;
		}else if(isLeaf!=null&&isLeaf>0){
			this.isParent=IS_PARENT_Y;
		}else{
			this.isParent=null;
		}
	}
	public Boolean getIsParent() {
		if(this.isLeaf==null){return IS_PARENT_N;}
		else{
		return this.isLeaf>0?IS_PARENT_Y:IS_PARENT_N;}
	}
	public void setIsParent(Boolean isParent) {
		this.isParent = isParent;
		if(isParent.equals(IS_PARENT_N)){
			this.isLeaf=IS_LEAF_Y;
		}else if(isParent!=null&&isParent.equals(IS_PARENT_Y)){
			this.isLeaf=IS_LEAF_N;
		}else{
			this.isLeaf=null;
		}
	}

	public boolean getIsParentBoolean() {
		return isParentBoolean;
	}

	public void setIsParentBoolean(boolean parentBoolean) {
		isParentBoolean = parentBoolean;
	}

	public String getIconPath() {
		return iconPath;
	}
	public void setIconPath(String iconPath) {
		this.iconPath = iconPath;
	}
	public Short getIsPrimary()
	{
		return isPrimary;
	}
	public void setIsPrimary(Short isPrimary)
	{
		this.isPrimary = isPrimary;
	}

	public Long getSn()
	{
		return sn;
	}
	public void setSn(Long sn)
	{
		this.sn = sn;
	}
	public String getOwnUserName()
	{
		return ownUserName;
	}
	public void setOwnUserName(String ownUserName)
	{
		this.ownUserName = ownUserName;
	}
	public String getCreateName()
	{
		return createName;
	}
	public void setCreateName(String createName)
	{
		this.createName = createName;
	}
	public String getUpdateName()
	{
		return updateName;
	}
	public void setUpdateName(String updateName)
	{
		this.updateName = updateName;
	}

	@Override
	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}
	/**
	 * 返回 组织ID
	 * @return 组织ID
	 */
	@Override
	public String getOrgId() {
		return orgId;
	}
	@Override
	public void setDemId(String demId) {
		this.demId = demId;
	}
	/**
	 * 返回 维度编号
	 * @return 维度编号
	 */
	@Override
	public String getDemId() {
		return demId;
	}

	@Override
	public String getDemName() {
		return demName;
	}
	/**
	 * 维度名称
	 */
	@Override
	public void setDemName(String demName) {
		this.demName = demName;
	}

	@Override
	public void setOrgName(String orgName){
		this.orgName =orgName;
	}
	/**
	 * 返回 名称
	 * @return 名称
	 */
	@Override
	public String getOrgName() {
		return orgName;
	}
	@Override
	public void setOrgDesc(String orgDesc) {
		this.orgDesc = orgDesc;
	}
	/**
	 * 返回 描述
	 * @return 描述
	 */
	@Override
	public String getOrgDesc() {
		return orgDesc;
	}
	@Override
	public void setOrgPathname(String orgPathname) {
		this.orgPathname = orgPathname;
	}
	/**
	 * 返回 组织路径
	 * @return 组织路径
	 */
	@Override
	public String getOrgPathname() {
		return orgPathname;
	}
	@Override
	public void setOrgSupId(String orgSupId) {
		this.orgSupId = orgSupId;
	}
	/**
	 * 返回 上级
	 * @return 上级
	 */
	@Override
	public String getOrgSupId() {
		return orgSupId;
	}

	@Override
	public String getOrgSupName()
	{
		return orgSupName;
	}
	@Override
	public void setOrgSupName(String orgSupName)
	{
		this.orgSupName = orgSupName;
	}
	@Override
	public void setPath(String path) {
		this.path = path;
	}
	/**
	 * 返回 路径
	 * @return 路径
	 */
	@Override
	public String getPath() {
		return path;
	}
	@Override
	public void setDepth(Integer depth) {
		this.depth = depth;
	}
	/**
	 * 返回 层次
	 * @return 层次
	 */
	@Override
	public Integer getDepth() {
		return depth;
	}
	@Override
	public void setOrgType(Long orgType) {
		this.orgType = orgType;
	}
	/**
	 * 返回 类型
	 * @return 类型
	 */
	@Override
	public Long getOrgType() {
		return orgType;
	}

	public void setCreatorId(String creatorId) {
		this.creatorId = creatorId;
	}
	/**
	 * 返回 建立人
	 * @return 建立人
	 */
	public String getCreatorId() {
		return creatorId;
	}
	@Override
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	/**
	 * 返回 建立时间
	 * @return 建立时间
	 */
	@Override
	public Date getCreateTime() {
		return createTime;
	}

	public void setUpdateId(String updateId) {
		this.updateId = updateId;
	}
	/**
	 * 返回 修改人
	 * @return 修改人
	 */
	public String getUpdateId() {
		return updateId;
	}
	@Override
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
	/**
	 * 返回 修改时间
	 * @return 修改时间
	 */
	@Override
	public Date getUpdateTime() {
		return  updateTime;
	}
	
	/**
	 * 负责人
	 */
	public void setOwnUser(String ownUser) {
		this.ownUser = ownUser;
	}

	/**
	 * 返回负责人
	 * @return 负责人
	 */
	public String getOwnUser() {
		return ownUser;
	}


   	public Integer getOnlineNum() {
		return onlineNum;
	}
	public void setOnlineNum(Integer onlineNum) {
		this.onlineNum = onlineNum;
	}
	
	
	public Short getIsRoot() {
		return isRoot;
	}
	public void setIsRoot(Short isRoot) {
		this.isRoot = isRoot;
	}
	@Override
	public Short getFromType() {
		return fromType;
	}
	@Override
	public void setFromType(Short fromType) {
		this.fromType = fromType;
	}
	
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getSupCode() {
		return supCode;
	}
	public void setSupCode(String supCode) {
		this.supCode = supCode;
	}
	/**
	 * @see Object#equals(Object)
	 */
	@Override
	public boolean equals(Object object)
	{
		if (!(object instanceof SysOrgChildren)) {
			return false;
		}
		SysOrgChildren rhs = (SysOrgChildren) object;
		return new EqualsBuilder()
		.append(this.orgId, rhs.orgId)
		.append(this.demId, rhs.demId)
		.append(this.orgName, rhs.orgName)
		.append(this.orgDesc, rhs.orgDesc)
		.append(this.orgPathname,rhs.orgPathname)
		.append(this.orgSupId, rhs.orgSupId)
		.append(this.path, rhs.path)
		.append(this.depth, rhs.depth)
		.append(this.orgType, rhs.orgType)
		.append(this.creatorId, rhs.creatorId)
		.append(this.createtime, rhs.createtime)
		.append(this.updateId, rhs.updateId)
		.append(this.updateTime, rhs.updateTime)
		.append(this.ownUser, rhs.ownUser)
		.append(this.sn, rhs.sn)
		.append(this.supCode, rhs.supCode)
		.isEquals();
	}

	/**
	 * @see Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		return new HashCodeBuilder(-82280557, -700257973)
		.append(this.orgId)
		.toHashCode();
	}

	/**
	 * @see Object#toString()
	 */
	@Override
	public String toString() 
	{
		return new ToStringBuilder(this)
		.append("orgId", this.orgId) 
		.append("demId", this.demId) 
		.append("orgName", this.orgName)
		.append("orgSupName", this.orgSupName)
		.append("isTenant", this.isTenant)
		.append("tenantId", this.tenantId)
		.append("parentTenantId", this.parentTenantId)
		.toString();
	}

	public String getTopOrgId() {
		return topOrgId;
	}
	public void setTopOrgId(String topOrgId) {
		this.topOrgId = topOrgId;
	}
	public String getCompanyId() {
		return companyId;
	}
	public void setCompanyId(String companyId) {
		this.companyId = companyId;
	}
	public String getCompany() {
		return company;
	}
	public void setCompany(String company) {
		this.company = company;
	}
	public Integer getOrgStaff() {
		return orgStaff;
	}
	public void setOrgStaff(Integer orgStaff) {
		this.orgStaff = orgStaff;
	}
	
}